package day8Exer;

/*
* 定义三角形类 Triangle,提供有参构造,公共方法,提供计算面积的方法
* */
public class Demo2 {
    public static void main(String[] args) {
        Triangle triangle = new Triangle(10.0,5.0);

        System.out.println("当前三角形面积为:"+triangle.getArea());
    }
}

//三角形类
class Triangle{

    //底边长
    private double base;

    //高
    private double height;

    public double getBase() {
        return base;
    }

    public void setBase(double base) {
        this.base = base;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    //有参构造，初始化属性值
    public Triangle(double base,double height){
        this.base = base;

        this.height = height;
    }

    //提供计算三角形面积的方法
    public double getArea(){
        return this.base * this.height/2;
    }
}
